<?php

namespace backend\components\rule;

use common\models\AdminModel;
use common\models\business\BusinessCustomer;
use yii\rbac\Rule;
use Yii;

class CustomerRule extends Rule
{

    public function execute($user, $item, $params)
    {
        $id = isset($params['id']) ? $params['id'] : null;
        if (!$id) {
            return false;
        }

        $model = BusinessCustomer::findOne($id);
        if (!$model) {
            return false;
        }
        $username = Yii::$app->user->id;
        $role = Yii::$app->user->identity->role;
        var_dump(1231);exit;
        if ($role == AdminModel::ROLE_ADMIN || $username == $model->oprator) {
            return true;
        }
        return false;

    }
}